package 二分查找;

import java.util.Arrays;
import java.util.Scanner;

public class test2 {
    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        int n = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        int target = in.nextInt();
        System.out.println(Arrays.toString(searchRange(nums, target)));
    }
    public static int[] searchRange(int[] nums, int target){
        // 分成两个区间来进行处理
        // [0,result-1]  [result,n-1] --> 找左端点(result)
        // [0,result]  [result+1,n-1] --> 找右端点(result)
        int n = nums.length;
        int[] ret = new int[]{-1,-1};
        if(nums.length==0) return ret;
        int left=0,right=n-1;
        while (left<right){
            // 最后左端点就是开头
            int mid = left+(right-left)/2;
            if(nums[mid]<target) left = mid+1;
            else
                right=mid;
        }
        // 要先判断是不是想要的点
        if(nums[left]!=target) return ret; // 不是
        ret[0] = left;

        left = 0;right = n-1;
        while (left<right){
            int mid = left+(right-left+1)/2;
            if(nums[mid]>target) right = mid-1;
            else
                left=mid;
        }
        if (nums[right]!=target){
            ret[1] = ret[0];
            return ret;
        }
        ret[1]=right;
        return ret;
    }
}
